import java.util.PriorityQueue;

public class Main {
    public static void main(String[] args) {

    }

    /**
     * 将数组和减半的最小操作次数
     * @param nums
     * @return
     */
    public static int halveArray(int[] nums) {
        PriorityQueue<Double> hash=new PriorityQueue<>((a,b)->b.compareTo(a));
        int n=nums.length;
        double sum=0;
        for(int i=0;i<n;i++){
            sum+=nums[i];
            hash.offer((double)nums[i]);
        }
        double ret=sum/2;
        int count=0;
        while(sum>ret){
            double cnt=hash.poll();
            double x=cnt/2.0;
            sum-=x;
            hash.offer(x);
            count++;
        }
        return count;
    }

    /**
     * 柠檬水找零
     * @param bills
     * @return
     */
    public static boolean lemonadeChange(int[] bills) {
        int n=bills.length;
        int res=0;
        int five=0,ten=0,twenty=0;
        if(bills[0]>5){
            return false;
        }
        for(int i=0;i<n;i++){
            if(bills[i]==5){
                five++;
            }else if(bills[i]==10){
                ten++;
                five--;
            }else{
                twenty++;
                if(ten>0){
                    ten--;
                    five--;
                }else{
                    five-=3;
                }
            }
            if(five<0){
                return false;
            }
        }
        return true;
    }
}